-
Notifications
You must be signed in to change notification settings - Fork 418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: bring elaborator in line with kernel for primitive projections #5822
Conversation
@leodemoura These changes are to support the inductive types created by the Without these changes, recursive structures lead to some elaborator panics, and they do not support numerical projection notation. |
Mathlib CI status (docs):
|
Refactors the `structure` command to support recursive structures. These are disabled for now, pending additional elaborator support in leanprover#5822. This refactor is also a step toward `structure` appearing in `mutual` blocks. Error reporting is now more precise, and this fixes an issue where general errors could appear on the last field. Closes leanprover#2512
Refactors the `structure` command to support recursive structures. These are disabled for now, pending additional elaborator support in #5822. This refactor is also a step toward `structure` appearing in `mutual` blocks. Error reporting is now more precise, and this fixes an issue where general errors could appear on the last field. Adds "don't know how to synthesize placeholder" errors for default values. Closes #2512
Refactors the `structure` command to support recursive structures. These are disabled for now, pending additional elaborator support in leanprover#5822. This refactor is also a step toward `structure` appearing in `mutual` blocks. Error reporting is now more precise, and this fixes an issue where general errors could appear on the last field. Adds "don't know how to synthesize placeholder" errors for default values. Closes leanprover#2512
82f0ad2
to
f8b55f1
Compare
The kernel supports primitive projections for all inductive types with one construtor. The elaborator was assuming primitive projections only work for "structure-likes", non-recursive inductive types with no indices. Enables numeric projection notation for general one-constructor inductives. Extracted from leanprover#5783.
8454e30
to
7352b23
Compare
Such types can be used with primitive projections. | ||
See also `Lean.matchConstStructLike` for a more restrictive version. | ||
-/ | ||
@[inline] def matchConstStructure [Monad m] [MonadEnv m] [MonadError m] (e : Expr) (failK : Unit → m α) (k : InductiveVal → List Level → ConstructorVal → m α) : m α := |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we rename these functions in the future? It is ok to merge with the current names, but I guess we will get confused in the future. I am referring to matchConstStructure
and matchConstStructureLike
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: matchConstStructure
and matchConstNonRecStructure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created an issue to track this suggestion #5891
Now that the elaborator supports primitive projections for recursive inductive types (#5822), enable defining recursive inductive types with the `structure` command, which was set up in #5842. Example: ```lean structure Tree where n : Nat children : Fin n → Tree def Tree.size : Tree → Nat | {n, children} => Id.run do let mut s := 0 for h : i in [0 : n] do s := s + (children ⟨i, h.2⟩).size pure s ``` Note for kernel re-implementors: recursive structures are exercising the kernel feature where primitive projections are valid for one-constructor inductive types in general, so long as the structure isn't a `Prop` and doesn't have any non-`Prop` fields, not just ones that are non-indexed and non-recursive. Closes #2512
The kernel supports primitive projections for all inductive types with one construtor. The elaborator was assuming primitive projections only work for "structure-likes", non-recursive inductive types with no indices.
Enables numeric projection notation for general one-constructor inductives.
Extracted from #5783.